package org.me;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import org.me.utils.Koneksi;

import android.app.Dialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class PresenceSet extends Dialog implements android.view.View.OnClickListener{
	
	Client client;
	ContactList contactList;
	XMPPConnection connection;
	EditText est;
	RadioButton av;
	RadioButton aw;
	RadioButton dnd;
	
	public PresenceSet(Client client) {
		super(client);
		this.client = client;
	}
	
	public PresenceSet(ContactList contactList) {
		super(contactList);
		this.contactList = contactList;
	}

	protected void onStart() {
        super.onStart();
        setContentView(R.layout.presence_dialog);
        getWindow().setFlags(4, 4);
        setTitle("XMPP Settings");
        connection = Koneksi.getInstance().getConnection();
        
        av = (RadioButton) findViewById(R.id.available);
		aw = (RadioButton) findViewById(R.id.away);
		dnd = (RadioButton) findViewById(R.id.dnd);
		
        est = (EditText) findViewById(R.id.status);
		est.setText(Koneksi.getStatus_message());
		
        Button set = (Button) findViewById(R.id.set);
        set.setOnClickListener(this);
    }

	@Override
	public void onClick(View v) {
		Presence presence = new Presence(Presence.Type.available);
		if (av.isChecked()) {
			presence.setMode(Mode.available);
		}
		else if (aw.isChecked()) {
			presence.setMode(Mode.away);
		}
		else if (dnd.isChecked()) {
			presence.setMode(Mode.dnd);
		}
		else {
			presence.setMode(Mode.available);
		}
        
		String st = est.getText().toString();
		Koneksi.setStatus_message(st);
        presence.setStatus(st);
        connection.sendPacket(presence);
        dismiss();
	}
}